import asyncio
from websocket import WebSocketServer


async def main():
    # 创建 WebSocket 服务器实例
    websocket_server = WebSocketServer()
    websocket_task = asyncio.create_task(websocket_server.start())  # 启动 WebSocket 服务器

    # 定时向 WebSocket 客户端发送心跳数据
    # async def send_data_periodically():
    #     while True:
    #         await asyncio.sleep(5)  # 每 5 秒发送一次数据
    #         await websocket_server.send("服务器定时发送消息：ping")

    # periodic_task = asyncio.create_task(send_data_periodically())

    # # 并发运行所有任务
    # # await asyncio.gather(websocket_task, periodic_task)
    
    await asyncio.gather(websocket_task)


if __name__ == "__main__":
    asyncio.run(main())

